//页面加载
// window.onload = function(){
    var pageCount = 1;
    function classOnload(a){
        console.log(a);

    var classId = localStorage.getItem("classId");
    // console.log(classId);
    var Json = {
            "pageSize":9,
            "pageIndex":a,
            "clazzId":classId
        }
        ajax.post(ajax.myUrl+"stu/clazzStu",Json,function(result){
        console.log(result);
        response(result);
        var data = result.dataset.stuList;
        var tbody = document.querySelector("tbody");
        tbody.innerHTML="";
        for(var i=0;i<data.length;i++){
            var newtr = document.createElement("tr");
            newtr.innerHTML=`
            <td>${data[i].fileName}</td>
            <td>${data[i].fileSex}</td>
            <td>${data[i].filePhone}</td>
            <td>${data[i].fileAddress}</td>
            <td>${data[i].fileSosPerson}</td>
            <td>${data[i].fileSosPhone}</td>
            <td><span class="remove">修改</span><span class="delete">删除</span></td>
            `;
            tbody.appendChild(newtr);
            // localStorage.setItem("userId"+i,data[i].userId);
        }

    //点击修改，弹出模态框
    //获取模态框
    var removeStudent = document.getElementsByClassName("removeStudent")[0];
    var remove = document.getElementsByClassName("remove");
    console.log(remove);
    console.log(data);
    for(var i=0;i<remove.length;i++){
        remove[i].onclick = function(){
            for(var j=0;j<remove.length;j++){
                if(this == remove[j]){
                    // console.log(j)
                    //模态框中显示此条内容
                    removeStudent.style.display = "block";
                    var filename = removeStudent.getElementsByClassName("filename")[0];
                    filename.value = data[j].fileName;
                    var fileaddress = removeStudent.getElementsByClassName("fileaddress")[0];
                    fileaddress.value = data[j].fileAddress;
                    // console.log(data[j].fileAddress);
                    var filepepole = removeStudent.getElementsByClassName("filepepole")[0];
                    filepepole.value = data[j].fileSosPerson;
                    var filephone = removeStudent.getElementsByClassName("filephone")[0];
                    filephone.value = data[j].filePhone;
                    var fileSosphone = removeStudent.getElementsByClassName("fileSosphone")[0];
                    fileSosphone.value = data[j].fileSosPhone;
                    var fileid = data[j].fileId;    //学生id
                    console.log(data[j].fileId);

                    //点击修改班级模态框中的确定或取消，模态框消失
                    var sure = removeStudent.getElementsByClassName("sure")[0];
                    sure.onclick = function(){
                        // console.log(clazzid);
                        var removeStudent = document.getElementsByClassName("removeStudent")[0]
                        removeStudent.style.display = "none";
                        console.log("11111");
                        var classId = localStorage.getItem("classId");
                        //获取修改用户模态框
                        var filename = removeStudent.getElementsByClassName("filename")[0];
                        var fileaddress = removeStudent.getElementsByClassName("fileaddress")[0];
                        var filepepole = removeStudent.getElementsByClassName("filepepole")[0];
                        var filephone = removeStudent.getElementsByClassName("filephone")[0];
                        var fileSosphone = removeStudent.getElementsByClassName("fileSosphone")[0];
                        var filesex = document.getElementById("sex");
                        console.log(filesex.value);
                        var Json7 = {
                            fileId:fileid,
                            clazzId:Number(classId),
                            fileName:filename.value,
                            fileSex:filesex.value,
                            filePhone:filephone.value,
                            fileAddress:fileaddress.value,
                            fileSosPerson:filepepole.value,
                            fileSosPhone:fileSosphone.value
                        }
                        console.log(Json7);
                        ajax.post(ajax.myUrl+"stu/updateStu",Json7,function(result){
                            console.log(result);
                        })
                    }
                    var cancel = removeStudent.getElementsByClassName("cancel")[0];
                    cancel.onclick = function(){
                        removeStudent.style.display = "none";
                    }
                }
            }
        }
    }


    //删除学生，点击删除，弹出提醒
    var dele = document.getElementsByClassName("delete");
    console.log(dele[0]);
    for(var i=0;i<dele.length;i++){
        dele[i].onclick = function(){
            for(var j=0;j<data.length;j++){
                if(this == dele[j]){
                    // console.log(data);
                    var fileid = Number(data[j].fileId);
                    var classid = Number(data[j].classId);
                    //点击删除，弹出提示
                    var tip = confirm("确认要删除吗？");
                    if(tip == true){
                        console.log("111");
                        //点击确定，触发事件
                        var Json5 = {
                            fileId:fileid,
                            clazzId:classid,
                            fileType:1
                        }
                        console.log(Json5);
                        ajax.post(ajax.myUrl+"stu/deleteStu",Json5,function(result){
                            console.log(result);
                        })
                    }
                }
            }
        }
    }


    })
}
// }



